package com.my.test;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

import com.google.zxing.WriterException;

/**
 * @author Administrator
 * 
 */
public class Qrest {

	/**
	 * @param path
	 *            创建地址
	 * @param fileName
	 *            创建文件名
	 * @param type
	 *            创建类型
	 * @return
	 */
	public static boolean createFile(String path, String fileName, String type) {
		String filenameTemp;
		Boolean bool = false;
		filenameTemp = path + "\\" + fileName + "." + type;
		File file = new File(filenameTemp);
		try {
			if (!file.exists()) {
				file.createNewFile();
				bool = true;
				System.out.println("success create file,the file is "
						+ filenameTemp);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bool;
	}

	public class Threr extends Thread{
		String con = null;
		String ret = null;
		public Threr(String con) {
			this.con = con;
		}
		@Override
		public void run() {
			super.run();
			ret = Qrest.createerweima(con);
		}
		public String getcon(){
			return ret;
		}
	}
	
	public static String createerweima(String content) {
		File directory = new File("");
		String thisfile;
		String addr = null;
		try {
			thisfile = directory.getCanonicalPath();
			DeleteFileUtil.deleteFile(thisfile + "\\erweima.jpg");
			Qrest.createFile(thisfile, "erweima", "jpg");
			String logUri = thisfile + "\\erweima.jpg";
			String outFileUri = logUri;
			int[] size = new int[] { 430, 430 };
			String format = "jpg";
			addr = InetAddress.getLocalHost().getHostAddress();
			try {
				new QRCodeFactory().CreatQrImage(content, format, outFileUri,
						logUri, size);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WriterException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		System.out.println(addr);
		return "http://"+addr + "/erweima.jpg";
	}

	public static void main(String[] args) throws IOException {
//
//		String content = "dsad";
//		File directory = new File("");
//		String thisfile = directory.getCanonicalPath();
//		DeleteFileUtil.deleteFile(thisfile + "\\erweima.jpg");
//		Qrest.createFile(thisfile, "erweima", "jpg");
//		String logUri = thisfile + "\\erweima.jpg";
//		String outFileUri = logUri;
//		int[] size = new int[] { 430, 430 };
//		String format = "jpg";
//		try {
//			new QRCodeFactory().CreatQrImage(content, format, outFileUri,
//					logUri, size);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (WriterException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		System.out.println(Qrest.createerweima("dsadsa"));
	}

}
